﻿/*****************************************************************************  

 Version: 0.1
 Website: http://www.visuagile.com/
 
 Copyright (c) Yoganand R. All rights reserved.
 For continued development and updates, visit http://yogsbreath.net
 
 ******************************************************************************/

using System;
using System.Collections.Generic;
using System.Text;
using System.Collections;
using Iesi.Collections.Generic;
using System.Collections.ObjectModel;
using System.Security.Principal;

namespace VisualAgile.Model
{
    public partial class User : IPrincipal
    {
        public static User Guest
        {
            get
            {
                return new User() { Email = "Guest@guest.com", Role = Role.Guest };
            }
        }

        public virtual string PublicIdentity
        {
            get
            {
                if (CanLogin) return Email;
                return "Guest";
            }
        }

        public virtual bool CanLogin { get { return IsAdministrator || IsLeadDeveoper; } }

        public virtual IIdentity Identity
        {
            get
            {
                bool isAuthenticated = !(Role.Name == Role.Guest.Name);
                return new Identity(isAuthenticated, this.Email);
            }
        }

        public virtual bool IsInRole(string role)
        {
            return this.Role.Name == role;
        }
      
        public virtual bool IsAdministrator { get { return Role.RoleID == Role.AdministratorId; } }
        public virtual bool IsLeadDeveoper { get { return Role.RoleID == Role.LeadDeveloperId; } }
        public virtual bool IsDeveloper { get { return Role.RoleID == Role.DeveloperId; } }

        /// <summary>
        /// Create Time
        /// </summary>
        public virtual DateTime CreateTime
        {
            get;
            set;
        }     

        /// <summary>
        /// Creator
        /// </summary>
        public virtual System.String Creator
        {
            get;
            set;
        }


        /// <summary>
        /// EmailID
        /// </summary>
        public virtual System.String Email
        {
            get;
            set;
        }

        /// <summary>
        /// User ID
        /// </summary>
        /// 
        public virtual Guid UserID
        {
            get;
            set;
        }

        /// <summary>
        /// User role
        /// </summary>
        /// 
        public virtual Role Role
        {
            get;
            set;
        }

        /// <summary>
        /// Project
        /// </summary>
        /// 
        public virtual Project Project
        {
            get;
            set;
        }


        /// <summary>
        /// Mobile
        /// </summary>
        public virtual System.String Mobile
        {
            get;
            set;
        }

        /// <summary>
        /// Password
        /// </summary>
        public virtual System.String Password
        {
            get;
            set;
        }

        /// <summary>
        /// Telephone
        /// </summary>
        public virtual System.String Telephone
        {
            get;
            set;
        }

        /// <summary>
        /// Username
        /// </summary>
        public virtual System.String UserName
        {
            get;
            set;
        }

        /// <summary>
        /// Defaultuser
        /// </summary>
        public virtual bool DefaultUser
        {
            get;
            set;
        }

        /// <summary>
        /// ValidFrom
        /// </summary>
        public virtual DateTime? ValidFrom
        {
            get;
            set;
        }


        /// <summary>
        /// ValidTo
        /// </summary>
        public virtual DateTime? ValidTo
        {
            get;
            set;
        }

        private ISet<Feelings> _feelings = new HashedSet<Feelings>();

        public virtual ReadOnlyCollection<Feelings> Feelings
        {
            get { return new List<Feelings>(_feelings).AsReadOnly(); }
        }

        public virtual void AddFeeling(Feelings feeling)
        {
            feeling.UserID = this.UserID.ToString();
            _feelings.Add(feeling);
        }

        public virtual void RemoveFeeling(Feelings n)
        {

        }
    }

    /// <summary>
    /// Simple implementation of IIdentity
    /// </summary>
    public class Identity : IIdentity
    {
        bool isAuthenticated;
        string name;

        public Identity(bool isAuthenticated, string name)
        {
            this.isAuthenticated = isAuthenticated;
            this.name = name;
        }

        public string AuthenticationType
        {
            get { return "Forms"; }
        }

        public bool IsAuthenticated
        {
            get { return isAuthenticated; }
        }

        public string Name
        {
            get { return name; }
        }
    }   
}
